package own.stu.jobgib.playown.mysql;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class Call {

    public static ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();

    public static void main(String[] args) {
        ExecutorService es = Executors.newCachedThreadPool();

        for (int i = 0; i < 100; i++) {
            es.execute(new Runnable() {

                @Override
                public void run() {
                    for (int j = 0; j < 1000; j++) {
                        String key = getSequence();
                        if (!map.contains(key)) {
                            System.out.println("put " + key);
                            map.put(key, key);
                        } else {
                            System.out.println(key + " is exists.");
                        }
                    }
                }
            });
        }

    }

    public static String getSequence() {
        List<Map<String, String>> list = null;
        try {
            list = JDBCTools.query("select nextval('user_code') as current");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String temp = list.get(0).get("current");
        return temp;
    }

}